package com.ymatou.iapi.fastturnover.testcase;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.fastturnover.parameter.addBean;
import com.ymatou.iapi.fastturnover.parameter.modifyBean;
import com.ymatou.iapi.fastturnover.service.addCall;
import com.ymatou.iapi.fastturnover.service.modifyCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.FastTurnoverService;
import com.ymttest.database.model.fastturnover.account_config_log;
import com.ymttest.database.model.fastturnover.account_config_logExample;
import com.ymttest.database.sqlwapper.fastturnover.account_config_logWrapper;
import com.ymttest.utils.EnvSetup;
/**
*修改配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_modify{
	private static modifyBean modifybean;
	private static modifyCall modifycall;
	
	Long fastturnover_seller=Long.parseLong(EnvSetup.getData("fastturnover_seller"));
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("修改配置");
	}

	@Before
	public void caseUp() {
		modifybean=new modifyBean();
		modifycall=new modifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(modifycall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modify_001() {
		Logger.start(true,"修改配置");
		try {
            //修改时间不能重复
			addBean addBean=FastTurnoverService.initAdd(fastturnover_seller);
			addCall addCall=FastTurnoverService.AddCall(addBean);
			
			SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
			java.util.Date start=formatter.parse(LocalDateTime.now().plusDays(4).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
			java.util.Date end=formatter.parse(LocalDateTime.now().plusDays(5).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
			
			modifybean.setStartTime(start);
			modifybean.setEndTime(end);
			modifybean.setSellerId(addBean.getSellerId());
			modifybean.setRate(4);
			modifybean.setOperator(addBean.getOperator());
			modifycall.setData(modifybean);
			modifycall.callService();			
			
			account_config_logExample example=new account_config_logExample();
			example.createCriteria().andSeller_idEqualTo(modifybean.getSellerId());
			account_config_logWrapper logWapper=new account_config_logWrapper();
			account_config_log log=logWapper.selectByExample(example).get(0);
			
			Logger.verifyEquals("200", modifycall.getCode1(), "验证code");
			Logger.verifyEquals("true", modifycall.getResult(), "验证result");
			
			Logger.verifyEquals(log.getRate(), modifybean.getRate(), "验证rate");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_modify_002() {
		Logger.start(true,"修改配置_关闭再修改，account_config_log表新增一条action_Type=1的数据");
		try {
            //修改时间不能重复
			addBean addBean=FastTurnoverService.initAdd(fastturnover_seller);
			addCall addCall=FastTurnoverService.AddCall(addBean);
			//关闭
			FastTurnoverService.close(addBean.getSellerId(), addBean.getOperator());
			
			SimpleDateFormat formatter = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
			java.util.Date start=formatter.parse(LocalDateTime.now().plusDays(4).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
			java.util.Date end=formatter.parse(LocalDateTime.now().plusDays(5).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
			
			modifybean.setStartTime(start);
			modifybean.setEndTime(end);
			modifybean.setSellerId(addBean.getSellerId());
			modifybean.setRate(4);
			modifybean.setOperator(addBean.getOperator());
			modifycall.setData(modifybean);
			modifycall.callService();			
			
			account_config_logExample example=new account_config_logExample();
			example.createCriteria().andSeller_idEqualTo(modifybean.getSellerId());
			example.setOrderByClause(" id desc");
			
			account_config_logWrapper logWapper=new account_config_logWrapper();
			account_config_log log=logWapper.selectByExample(example).get(0);
			
			Logger.verifyEquals("200", modifycall.getCode1(), "验证code");
			Logger.verifyEquals("true", modifycall.getResult(), "验证result");
			
			Logger.verifyEquals(log.getRate(), modifybean.getRate(), "验证rate");
			Logger.verifyEquals(log.getAction_type(), 2, "验证action_type 1，新增，2修改，3关闭");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}